package com.ymatou.authapp.testcase;

import java.util.ArrayList;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.ymatou.authapp.parameter.LockUserRequestDtoBean;
import com.ymatou.authapp.parameter.UserLoginByCookieRequestDtoBean;
import com.ymatou.authapp.service.LockUserRequestDtoCall;
import com.ymatou.authapp.service.UnLockUserRequestDtoCall;
import com.ymatou.authapp.service.UserLoginByCookieRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymt.utils.tag.P3;
import com.ymttest.database.mongo.ULC201406Bean;
import com.ymttest.database.mongo.ULC201406Wapper;
import com.ymttest.utils.constant.ECode;

/**
*从cookie登陆接口
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_UserLoginByCookieRequestDto{
	private static UserLoginByCookieRequestDtoBean userloginbycookierequestdtoBean;
	private static UserLoginByCookieRequestDtoCall userloginbycookierequestdtoCall;
	
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("从cookie登陆接口");
	}

	@Before
	public void caseUp() {
		userloginbycookierequestdtoBean=new UserLoginByCookieRequestDtoBean();
		userloginbycookierequestdtoCall=new UserLoginByCookieRequestDtoCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(userloginbycookierequestdtoCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	
	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_UserLoginByCookieRequestDto_001() {
		Logger.start(true,"从cookie登陆成功");
		try {
			userloginbycookierequestdtoBean.setUserId(95);
			userloginbycookierequestdtoBean.setUserType(1);
			userloginbycookierequestdtoBean.setClientIp("12.15.2.32");
			userloginbycookierequestdtoBean.setDescription("从cookie登陆");
			userloginbycookierequestdtoBean.setSourceType("App");
			userloginbycookierequestdtoBean.setToken("407BA884F75D6811F13CB939015A180D3F538ED859E740F12BAB863097122B03");
			userloginbycookierequestdtoCall.setData(userloginbycookierequestdtoBean);
			userloginbycookierequestdtoCall.callService();			
			
			ULC201406Wapper wapper = new ULC201406Wapper();
			ULC201406Bean userModel = wapper.getULCInfoByUid(95);
			Logger.verifyEquals(true, userloginbycookierequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals("OK", userloginbycookierequestdtoCall.getResult().get("Code"), "验证Code");
			Logger.verifyEquals(userModel.getToken(), userloginbycookierequestdtoCall.getResult().get("Token"), "验证Token信息");
			Logger.verifyEquals(Double.valueOf(userModel.getuId()), userloginbycookierequestdtoCall.getResult().get("UserId"), "验证用户Id");
			Logger.verifyEquals(userModel.getlBills().getLoginId(), userloginbycookierequestdtoCall.getResult().get("LoginId"), "验证登陆Id");
			Logger.verifyEquals(userModel.getlBills().getEmail(), userloginbycookierequestdtoCall.getResult().get("LoginEMail"), "验证邮箱");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserLoginByCookieRequestDto_002() {
		Logger.start(false,"输入不存在的用户Id, 登陆失败");
		try {
			userloginbycookierequestdtoBean.setUserId(-2);
			userloginbycookierequestdtoBean.setUserType(1);
			userloginbycookierequestdtoBean.setClientIp("12.15.2.32");
			userloginbycookierequestdtoBean.setDescription("从cookie登陆");
			userloginbycookierequestdtoBean.setSourceType("App");
			userloginbycookierequestdtoBean.setToken("407BA884F75D6811F13CB939015A180D3F538ED859E740F12BAB863097122B03");
			userloginbycookierequestdtoCall.setData(userloginbycookierequestdtoBean);
			userloginbycookierequestdtoCall.callService();			
				
			Logger.verifyEquals(false, userloginbycookierequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(ECode.AUTH_NOTFOUND_USER1, userloginbycookierequestdtoCall.getMsg(), "验证Msg信息");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserLoginByCookieRequestDto_003() {
		Logger.start(false,"不输入Token,登陆失败");
		try {
			userloginbycookierequestdtoBean.setUserId(95);
			userloginbycookierequestdtoBean.setUserType(1);
			userloginbycookierequestdtoBean.setClientIp("12.15.2.32");
			userloginbycookierequestdtoBean.setDescription("从cookie登陆");
			userloginbycookierequestdtoBean.setSourceType("App");
			userloginbycookierequestdtoCall.setData(userloginbycookierequestdtoBean);
			userloginbycookierequestdtoCall.callService();			
				
			Logger.verifyEquals(false, userloginbycookierequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(ECode.AUTH_INVALID_TOKEN, userloginbycookierequestdtoCall.getMsg(), "验证Msg信息");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserLoginByCookieRequestDto_004() {
		Logger.start(false,"用户被锁定，登陆失败");
		try {
			Logger.comment("锁定用户：95");
			LockUserRequestDtoBean lockuserrequestdtoBean = new LockUserRequestDtoBean();
			LockUserRequestDtoCall lockuserrequestdtoCall = new LockUserRequestDtoCall();
			UnLockUserRequestDtoCall unlockuserrequestdtoCall = new UnLockUserRequestDtoCall();
			ArrayList<Integer> users = new ArrayList<Integer>();
			users.add(95);
			lockuserrequestdtoBean.setUserId(users);
			lockuserrequestdtoBean.setDescription("test: lock user 95");
			lockuserrequestdtoBean.setOperating("lock user");
			lockuserrequestdtoCall.setData(false, lockuserrequestdtoBean);
			lockuserrequestdtoCall.callService();
			
			Logger.comment("用户95尝试从cookie登陆");
			userloginbycookierequestdtoBean.setUserId(95);
			userloginbycookierequestdtoBean.setUserType(1);
			userloginbycookierequestdtoBean.setClientIp("12.15.2.32");
			userloginbycookierequestdtoBean.setDescription("从cookie登陆");
			userloginbycookierequestdtoBean.setSourceType("App");
			userloginbycookierequestdtoBean.setToken("407BA884F75D6811F13CB939015A180D3F538ED859E740F12BAB863097122B03");
			userloginbycookierequestdtoCall.setData(userloginbycookierequestdtoBean);
			userloginbycookierequestdtoCall.callService();	
			
			Logger.verifyEquals(false, userloginbycookierequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(ECode.AUTH_USER_ISLOCKED, userloginbycookierequestdtoCall.getMsg(), "验证Msg信息");
			
			Logger.comment("恢复数据，解锁用户：95");
			unlockuserrequestdtoCall.setData(lockuserrequestdtoBean);
			unlockuserrequestdtoCall.callService();		
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category(P3.class)
	@TestCase
	public void Tc_UserLoginByCookieRequestDto_005() {
		Logger.start(false,"输入无效Token,登陆失败");
		try {
			userloginbycookierequestdtoBean.setUserId(100);
			userloginbycookierequestdtoBean.setUserType(1);
			userloginbycookierequestdtoBean.setClientIp("12.15.2.32");
			userloginbycookierequestdtoBean.setDescription("从cookie登陆");
			userloginbycookierequestdtoBean.setToken("451522");
			userloginbycookierequestdtoBean.setSourceType("App");
			userloginbycookierequestdtoCall.setData(userloginbycookierequestdtoBean);
			userloginbycookierequestdtoCall.callService();			
				
			Logger.verifyEquals(false, userloginbycookierequestdtoCall.getSuccess(), "验证是否成功");
			Logger.verifyEquals(ECode.AUTH_NOTMATCH_TOKEN, userloginbycookierequestdtoCall.getMsg(), "验证Msg信息");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	
}